<template>
	<div class="count">
		<h2>当前求和为:{{sum}}</h2>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment">加</button>
		<button @click="decrement">减</button>
		<button @click="incrementIfOdd">当前和为奇数再加</button>
		<button @click="incrementWait">等一等再加</button>
	</div>
</template>

<script>
	export default {
		name:'Count',
		data() {
			return {
				n:1,
				sum:0,
			}
		},
		methods: {
			//加法
			increment(){
				this.sum += this.n
			},
			//减法
			decrement(){
				this.sum -= this.n
			},
			//和为奇数再加
			incrementIfOdd(){
				if(this.sum % 2){
					this.sum += this.n
				}
			},
			//等一等再加
			incrementWait(){
				setTimeout(()=>{
					this.sum += this.n
				},500)
			},
		},	
	}
</script>

<style>
	.count{
		background-color: skyblue;
		padding: 20px;
	}
	select,button{
		height: 30px;
		margin-right: 10px;
	}
</style>